# Maintainer: Gustavo Alvarez <sl1pkn07@gmail.com>
# Contributor: Mikhail Vorozhtsov <mikhail.vorozhtsov@gmail.com>
# Contributor: Nagisa <simonas@kazlauskas.me>
# Contributor: Misc <andreas.reis@gmail.com>
# Contributor: Jeagoss <jgoliver@jeago.com>

#########################
## -- Build options -- ##
#########################

_use_clang=1            # Use clang compiler. Results in faster build and smaller chromium.
_use_pax=0              # If set 1, change PaX permisions in executables NOTE: only use if use PaX environment (IN TEST)
GYP=0 # set to 1 to use gyp or 0 to use gn
inTMPFS=1 # 1 means compile in /tmp (assumed u have enough ram and it's tmpfs)

##############################################
## -- Package and components information -- ##
##############################################
pkgname=chromium-dev-git
pkgver=43.0.2340.0_r978.bbac0e7
pkgrel=1
pkgdesc='The open-source project behind Google Chrome (Dev Channel)'
arch=('i686' 'x86_64')
url="http://www.chromium.org/"
license=('BSD')
#TODO: need to update these libs
depends=('desktop-file-utils' 'hicolor-icon-theme' 'gtk2' 'icu' 'libevent' 'libexif' 'libpulse' 'libwebp' 'libxslt' 'libxss' 'minizip' 'bzip2'
         'nss' 'pciutils' 're2' 'snappy' 'speech-dispatcher' 'speex' 'ttf-font' 'xdg-utils') #'libvpx' 'protobuf' 'opus' 'jsoncpp'
makedepends=('elfutils' 'gperf' 'ninja' 'perl-json' 'python2-jinja' 'python2-simplejson' 'python2-ply' 'subversion' 'yasm' 'git' 'depot-tools-git' 'bzip2' 'ccache') # 'libsrtp'
optdepends=(#'chromium-pepper-flash-dev: PPAPI Flash Player [Dev Channel]'
            'kdebase-kdialog: needed for file dialogs in KDE'
            'gnome-keyring: for storing passwords in GNOME keyring'
            'kdeutils-kwalletmanager: for storing passwords in KWallet')
provides=('chromium-dev') # 'chromedriver')
conflicts=('chromedriver')
if test "$GYP" = "0"; then
  #gn
  makedepends+=('libgnome-keyring' 'libtinfo')
  #libgnome-keyring is required due to some error about pkg-config
  #libtinfo is required due to some missing wrapper symlinks to nscurses
else
  #gyp
  optdepends+=('libgnome-keyring: for storing passwords in GNOME keyring [should be installed prior to compiling this chromium]')
fi
[ "${CARCH}" = "x86_64" ] && makedepends+=('lib32-gcc-libs' 'lib32-zlib') && warning "To build need active [multilib] repository, if not , fail build"
install=chromium-dev.install
backup=('etc/chromium-dev/default')
_folder="${startdir}/fetch_gclient_base/checkout_root"
_srcfolder="${_folder}/src"
if test "$GYP" = "1"; then
  _reldir="out/Release" #anything else won't work, even when copied
else
  _reldir="out/Default"
fi
if test "$inTMPFS" = "1"; then
  _reldir="/tmp/${_reldir}"
fi
#_reldirtmp="/tmp/out/Release"
#set
#####"https://commondatastorage.googleapis.com/chromium-browser-official/chromium-${pkgver}.tar.xz"
        # Patch from Gentoo
#######"${_folder}::git+https://chromium.googlesource.com/chromium/src.git"
#set | grep -i srcdir # nope not available at this point
##patch3='0100_item_not_found.patch' #already included in 0700 below
#patch4='0200_no_warnings_as_errors.patch'
##patch5='0300_use_system_clang.patch'
###patch6='0400_it_is_plural.patch' #useless!
##patch7='0500_message_center_disabled.patch'
#patch8='0600_fix_AutofillDialogController.patch'
##patch9='0700_fix_rest_of_compilation_errors_until_linking.patch'
##patchavoidfetch='avoid_fetching_stuff.patch'
##patchall='all.patch'
#patch10='0800_small_fixes.patch'
allpatches=(
0200_no_warnings_as_errors.patch
0300_use_system_clang.patch
0500_message_center_disabled.patch
0600_fix_AutofillDialogController.patch
#0800_small_fixes.patch
0900_autofill_disabled.patch
1000_pepper_compile_error.patch
1100_plugins_disabled.patch
1200_signin_fix.patch
1300_background_fix.patch
#1400_hotword_disabled.patch
1400_make_linking_work.patch
)
source=(
#        "syncc"
#        "pythonic"
        'http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/www-client/chromium/files/chromium-system-jinja-r7.patch'
        'chromium-dev.desktop'
        'chromium-dev.sh'
        'chromium-dev.default'
        'chromium-dev.xml'
        # Misc Patches
#        'http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/www-client/chromium/files/chromium-libsecret-r0.patch'
        # Patch from crbug [chromium bugtracker]
        #own patches
        "${allpatches[@]}"
        )
#"`curl -sL "https://commondatastorage.googleapis.com/chromium-browser-official/chromium-${pkgver}.tar.xz.hashes" | grep sha1 | cut -d " " -f3`"

#'689cee917bd8a81edb4e640d551eca8bbbca9fa7c8d0afbca513cd911880773e7bfa0e3d558ca770afb418c6e0b42c28edb08b4792de900df1fb0b58afba22ee'
#'SKIP'
sha512sums=('689cee917bd8a81edb4e640d551eca8bbbca9fa7c8d0afbca513cd911880773e7bfa0e3d558ca770afb418c6e0b42c28edb08b4792de900df1fb0b58afba22ee'
            '5b1721cc273642565bc617d732c41abdca5245c42608cd9bceb60d39cbdb3e22af183916feaef52f6b2eb748dfc8f260632e99dd298b12362e48fd8fb13e9214'
            '9c250d08cbc7c281b5c639971d67e2fbc0aea572bb3c3b9d568fc9f9ef9166e72cb98d90331fa369bdb4d8f2531d54acd9d2ab6fad4119f7062ddd9da87b957e'
            '83c247adc419b0ed7c055bb7d7cb59d4b13510af96ce6d655e236221398c7b86355308b2a86233d0d561cd51d1fb79cb32435f0e9ce12a578b4b804e88a14d54'
            '8eccbf694cb26a530b35a3750f308f489f6fbcc6dbb74064117e0117d5e67a95e0f5a713c76ff8c86149930e3965aa8186307afb773b8da6c301fda7201db3fa'
            'ecb33304d6f5cbfcd67b365ce0d94f0f39db8435e0f444acf81e6ac90db72c896279ebf798fd6c95a88fcbd511fef0f9d396611bb66aec6e34296ebe2016a8f8'
            '693fbc61bf78683dbd91c60496d5e0a8282abd222abb0248cb564bfdde91feef1179933499dfb0100f5ce96006fa1fe88a955af11e103911bea84522ba54189b'
            'b195d667aeaa906162ecade93e939bab6f275d17b0142f6e7410c77a33f761c1887c6c6593cb1061eb2917f536c6ca2009cf1b5a24c76f1116742d9046a4ff50'
            'd1a63bff3004b6081580241623700ae36500766b09b691c6eaabdb45aa34b5a94c8bdfcf42e99df62b8d6c6d88ac0bf75f0eb90036d4f5850cae22ffac00ae4a'
            '93dded9bd398ef496c063fb8c6fb37cefd697ac062dac3102ee3c807cf6ce472b8837d0d24bd850f0cc79c9c5e471301829679258fe3589a85a189097b7a96bd'
            'aa40b391f9b94bcafe887ab7a2160986c966475d74d28c07b9bf805c7340f4592f9dc325a910b1c67e0434afbcd5977ed9722134cb3584eae180edb139c1ea51'
            '4483d9a8cdd876ba49349dfce6c8d5a2309ba8df5c45abad6be240666438554a087c51664f922e8e0122e9dc8a2e8a865d507f001a50b475e679af79b26b1564'
            '51d710b00cea2d87a7dc6aa2c922ae1036c57872fa15f0d7f53dbf8c12f995be8acd9e3b39d3a6911f5bd2c89401d10711cad878205581e7a1c88bab053328b9'
            '9c15175b16ce06a1d6ee50432440c37c7f8fa4c3817884ac9b33fc3e5de6a7f00fcf58bc840d1b61e8918a02dfc2ffbff39ae612717fc604d009a4e38ae7280b'
            '0fb065d699d398389222b625b1f2abceee83058a59c8ee635353915f8f561125c13a40273587cd593f520ad12d4daa9373e28065c4b0ddaeb1c0e05eef5911ed')
options=('!strip')
#noextract=("chromium-${pkgver}.tar.xz")
#_gitname=chromium

# Google API keys (see http://www.chromium.org/developers/how-tos/api-keys)
# Note: These are for Arch Linux use ONLY. For your own distribution, please
# get your own set of keys. Feel free to contact foutrelis@archlinux.org for
# more information.
# <keys removed> #emacs

################################################
## -- Don't touch anything below this line -- ##
################################################

[ "${CARCH}" = "i686" ] && _target_arch="ia32"
[ "${CARCH}" = "x86_64" ] && _target_arch="x64"

# If use PaX environment, need 'paxctl'
[ "${_use_pax}" = "1" ] && makedepends+=('paxctl')

if [ "${_use_clang}" = "1" ]; then
  makedepends+=('clang')
  _clang_version="$(clang --version | grep clang | cut -d ' ' -f3)"
fi
 
if test "$GYP" = "1"; then
  # Are we in Gnome?
  _use_gnome=0
  #emacs# force don't use gnome!
  #if [ -f /usr/lib/libgnome-keyring.so ]; then
  #  depends+=('libgnome-keyring')
  #  _use_gnome=1
  #fi
  
  # Use Pulseaudio?
  _use_pulseaudio=0
  if [ -x /usr/bin/pulseaudio ]; then
    _use_pulseaudio=1
  fi
fi

getchromiumver() {
    pushd -- "${_srcfolder}" >/dev/null 2>&1
    export PATH="${srcdir}/python-path:$PATH"
    build/util/version.py -f chrome/VERSION -t "@MAJOR@.@MINOR@.@BUILD@.@PATCH@"
    #FIXME: allow tag --list first and if empty, do the version.py - if the latter fails pkgver won't be changed apparently; that's good because it will have to fail until version.py gets downloaded
    # tags dont exit with --nohistory: git tag --list --sort="-v:refname" | head -1
    popd -- >/dev/null 2>&1
}

pkgver() {
    cd "${_srcfolder}"
    printf "%s_r%s.%s" "$(getchromiumver)" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
    printf "%s_r%s.%s" "$(getchromiumver)" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" >&2
}

  # TODO
  # -Duse_system_hunspell=1    | upstream changes needed
  # -Duse_system_jsoncpp=1     | need newer jsoncpp (0.6.0-rcX)
  # -Duse_system_libsrtp=1     | https://bugs.gentoo.org/show_bug.cgi?id=459932
  # -Duse_system_libvpx=1      | http://crbug.com/347823
  # -Duse_system_libusb=1      | http://crbug.com/266149
  # -Duse_system_opus=1        | https://code.google.com/p/webrtc/issues/detail?id=3077
  # -Duse_system_protobuf=1    | https://bugs.gentoo.org/show_bug.cgi?id=503084
  # -Duse_system_sqlite=1      | http://crbug.com/22208
  # -Duse_system_ssl=1         | http://crbug.com/58087
  # -Duse_system_openssl=1     | migrate to boringssl


#if test "$GYP" = "1"; then #need this for both gyp and gn, for cleaning which in turn is needed for sync
#WARNING: changing any of these requires prepare() or just cleaning all folders then gclient sync, just in case a transition from =1 to =0 happened  (not from =0 to =1 though)
_use_system=(
    -Duse_system_expat=1
    -Duse_system_ffmpeg=0
    -Duse_system_flac=1
    -Duse_system_fontconfig=1
    -Duse_system_harfbuzz=1
    -Duse_system_icu=1
    -Duse_system_jsoncpp=0  #TODO: do this =1 and install jsoncpp
    -Duse_system_libxnvctrl=0
    -Duse_system_libevent=1
    -Duse_system_libexif=1
    -Duse_system_libjpeg=1
    -Duse_system_libpng=1
    -Duse_system_libusb=0
    -Duse_system_libvpx=0
    -Duse_system_libwebp=1
    -Duse_system_libxml=1
    -Duse_system_libxnvctrl=0 #addon
    -Duse_system_libxslt=1
    -Duse_system_minizip=1 #addon
    -Duse_system_nspr=1 #addon
    -Duse_system_openssl=0
    -Duse_system_opus=0
    -Duse_system_protobuf=0
    -Duse_system_re2=1
    -Duse_system_snappy=1
    -Duse_system_speex=1
#    -Duse_system_stlport=1 #out
    -Duse_system_sqlite=0 #addon
    -Duse_system_ssl=0 #addon
    -Duse_system_v8=0 #addon
    -Duse_system_yasm=1
    -Duse_system_zlib=1
    -Duse_system_xdg_utils=1

    -Duse_system_bzip2=1 #out?
    )
#fi

#_cleanfolder(){
#  # $1 is folder to clean
#  # it's actually git stash-ed
#  if [ -z "$1" ]; then
#    error "passed no parameter"
#    exit 1
#  fi
#  if [ -d "$1" ]; then
#    pushd "$1"
##  msg2 "before:"
##  git status
#  git stash  #yep can't replace this because it somehow does hide the libsecret patch on chrome/chrome_browser.gypi  but checkout . and clean  below  do not! XXX: KEEP stash because we don't want to remove newly created folders like '1' (where i used to put moved folders temporarily) also execute git stash clear  sometime
###  git checkout .  #can't reapply patches hmm; because untracked files are not wiped with git checkout
###  git clean -fd  #ok needs this too!
##  msg2 "after:"
##  git status
#    popd
#  else
#    msg2 "ignoring inexistent dir '$1'"
#  fi
#}


removestuff() {
#use like this removestuff <<EOF
#file1
#folder2
#EOF
#XXX: looks like the above can't contain {} or *   well it can but it won't be expanded (globbing?)
  if test -z "$1"; then
    error "you didn't pass a folder name as parameter"
    exit 1
  fi

#  read -r -d '' -a templist <&0 || true  #prevent EOF returning exit code 1 and due to set -e fail PKGBUILD!

  msg2 "Removing stuff from folder '$1'"
  pushd "$1" >/dev/null
#  echo ${templist[@]}
#TODO: maybe foreach and make sure they do not contain a first slash! as they are meant to be relative to current folder
#  cat <<<"$templist" | 
  xargs --no-run-if-empty --verbose --exit rm -rf -- # <<< "${templist[@]}"  #XXX: stuff is already comming from stdin
  # ${templist[@]}
  popd >/dev/null
#  msg2 "done."
}

#updgclient_entries() {
##  pushd "${_folder}"
#  msg2 "removing unwanted sources from fetching..."
#  sed -re '/^  .src\/(chrome\/test\/|testing\/|third_party\/(libjingle|libphonenumber|safe_browsing|webrtc)).*$/d' -i "${_folder}/.gclient_entries" 
#  #-re "s|  'src/testing/.\*$||g" -re "s|  'third_party/\\(libjingle\\|libphonenumber\\|safe_browsing\\|webrtc\\).\*$||g" -i ".gclient_entries"
##  popd
#}

lepatch() {
#  echo $-
#  trap -p
  #since we're inside PKGBUILD we know `set -e` is on, so we don't save its state
  set +e
#  set +o pipefail #unaffected by the setting of this
  #now we need to save/restore the ERR trap or else it gets triggered regardless of the +e setting
  local restoretrap="`trap -p | grep -E "ERR$"`"
  #clear ERR trap so we don't fail when patch or grep fails
  trap -- "" ERR
#XXX: PKGBUILD has: set -e which is why the following fails when grep doesn't find strings even if you add ` ; true`:
  msg2 "patch $*" #XXX: $* because $@ adds \n after first param O_o so msg2 doesn't show the rest
  patch "$@" | grep -B10 -E "(FAILED --|ignored|The next patch|which does not)"
  local ps=("${PIPESTATUS[@]}") #gets reset after running any statement, so need to save it
  #local ps="${PIPESTATUS[@]}" #gets reset after running any statement, so need to save it
#  declare +g -a "ps"

  #restore
  set -e
  eval "$restoretrap" 
#  $restoretrap #yep, unquoted, but doesn't work:
  #/usr/bin/makepkg:274+ trap -- ''\''error_function' '$pkgfunc'\''' ERR
  #PKGBUILD: line 274: trap: $pkgfunc': invalid signal specification
  #actual reported line by trap -p is: trap -- 'error_function $pkgfunc' ERR

#  set -o pipefail
# dsaodhasiohdoa #should fail - ok that worked!
  patch_ec="${ps[0]}"
  grep_ec="${ps[1]}"
  if test "$grep_ec" -eq 0; then # -o "$patch_ec" -ne 0; then
    #grepping found strings - this is bad
    error "patching failed! reapply changes in .rej files above and remake the patch, update patch file and re-execute this. Everything else should be patched because we're using only one patch UNLESS it's the first jinja patch, see the cmd above; For 'Skipping patch.' you just need to ignore those and re-run ./makepatchu and put the updated patch in place"
    ret=126
  else
    if test "$patch_ec" -ne 0; then
      ret="$patch_ec"
      error "patch command failed! exit code: $ret"
    fi
  fi
  return $ret
}

prepare() {
#  pwd = $srcdir = /tmp/makepkg/chromium-dev-git/src    at this point
  ##############################
  ## -- Get ready to build -- ##
  ##############################

  # Set Python2 path
  mkdir -p python-path
  ln -s /usr/bin/python2 "${srcdir}/python-path/python" || echo whatever
  export PATH="${srcdir}/python-path:$PATH"

  
#set|grep -i error
#exit 1
  pwd
  mkdir -p "${_folder}"
  cd "${_folder}"

# fetch if first time, sync if any other time
  if test -d "${_srcfolder}" -a -f ".gclient"; then
#    if [ ! -f ".gclient" ]; then
#      error ".gclient must exist in `pwd` Something went too wrong! must run fetch instead"
#      exit 1
#    fi

#    pushd "${_srcfolder}"
#    #overwrite all changes, usually made by us in this prepare() function
#    #let's hope user hasn't made any, they will be lost only when using checkout below (commented out now)
#    #changes will be stashed
#    #this is needed for gclient sync to work below
#
##fails
##    "${srcdir}/pythonic" build/linux/unbundle/replace_gyp_files.py "${_use_system[@]}" --undo
#
#    for each in ${_use_system[@]}; do
#      each2="$(echo -n "$each" | sed -e "s|.*_\(.*\)=[0-9]|\1|")"
#      msg2 "cleaning $each2"
#      _fold="third_party/${each2}"
#      if [ -d "$_fold" ]; then
#        _cleanfolder "${_fold}"
#      else
#        warning "ignoring inexistent folder $_fold"
#      fi
#    done

#    _cleanfolder "third_party/WebKit" #because of the jinja-r7.patch
#    _cleanfolder "third_party/webrtc"

#    popd

    msg2 "stashing changes..."
    gclient recurse --no-progress -- git stash || echo "ignoring failure" # >/dev/null
    gclient recurse --no-progress -- git stash clear >/dev/null || echo "ignored fails - because it's probably first run with empty src folder"
    msg2 "sync-ing from the internet"
    pushd "${_srcfolder}"
    find . -type f -name '*.sedified' -or -type f -name '*.rej' -or -type f -name '*.cedified' | xargs rm -f -- 
#TEMP:    find . -type f -name '*_browsertest.*' | xargs rm -f --
#    TODO: is this really needed?: guess so, but should check updating instructions again sometime
    if test -d '.git'; then
      msg2 "git pull (because gclient sync doesn't update src/"
#      git pull --verbose --tags --depth=1  || ( git checkout master && git pull --tags --depth=1 --verbose )
#      git pull --progress --verbose || ( git checkout master && git pull --verbose --progress )
      git pull --verbose || ( git checkout master && git pull --verbose ) || echo "ignoring - because it's probably first run with empty src folder"
    fi
    popd
    #-vvv
    
    #"${srcdir}/pythonic"
#    gclient update --nohooks -v --no-history --jobs 8
#ok: need to modify .gclient_entries before syncing from internet! but it's part of gclient.py
#    updgclient_entries
    #gclient sync -vvv --nohooks --no-history --jobs 1
    msg2 "gclient sync"
    #--with_tags  #doesn't fetch tags if repo is already fetched
    gclient sync --nohooks --no-history --jobs 8  #not using -v , in order to be quiet; ok --shallow is bad, apparently!

#    pwd
    gnexe="${_srcfolder}/buildtools/linux64/gn"
    if ! test -f "$gnexe"; then
      msg2 "gn executable isn't there, so this is probably the first run"
      msg2 "downloading it now..."
      download_from_google_storage --no_resume --platform='linux*' --bucket chromium-gn -s src/buildtools/linux64/gn.sha1 | grep -v -- 'CommandException: Invalid command "stat".'
      #^ this will fail with: "CommandException: Invalid command "stat"."
      # so using that grep which only returns 1 if that pattern isn't found should work around this and still fail if something else happened - but we can't see it :) unless using that -v to show anything other than that pattern
    fi
    if ! test -x "$gnexe"; then
      chmod a+x "$gnexe"
    fi
  else
    error "unsupported! the src folder must exist and .gclient file as a sibling too!"
    exit 22
#    msg2 "no src folder '${_srcfolder}' fetching..."
#    msg2 "Note: incomplete fetches should be restarted after you remove the src folder! (or so fetch says: that it doesn't support incomplete fetches)"
#    fetch --nohooks --no-history chromium

    #XXX: this patch is kinda useless to do after the fetch, because it already fetched everything that the patch is trying to exclude
#    patch -p1 -i "${srcdir}/$patchavoidfetch"
#    updgclient_entries
    # ^ this runs: gclient sync --nohooks --no-history
    #TODO: now how can I put a  -v  in there?
    # [0:00:01] remote: Sending approximately 2.72 GiB ...        
    # with --no-history that is
  fi

  cd "${_srcfolder}"
  pwd


removestuff "." <<EOF
chrome/browser/extensions/api/gcd_private
browser/extensions/api/mdns
chrome/browser/devtools/device/webrtc
chrome/browser/devtools/webrtc_device_provider_resources.gyp
chrome/browser/extensions/api/mdns
third_party/skia/src/opts/SkBlitRow_opts_arm.cpp
third_party/skia/src/opts/SkBlitRow_opts_arm_neon.cpp
EOF

removestuff "third_party/skia/src" <<EOF
opts/SkBitmapProcState_arm_neon.cpp
opts/memset32_neon.S
opts/SkBitmapProcState_filter_neon.h
opts/SkTextureCompression_opts_neon.h
opts/memset16_neon.S
opts/SkBitmapProcState_matrixProcs_neon.cpp
opts/Sk2x_neon.h
opts/SkBlitRow_opts_arm_neon.h
opts/SkBlitMask_opts_arm_neon.h
opts/SkMorphology_opts_neon.h
opts/SkBlurImage_opts_neon.h
opts/SkTextureCompression_opts_neon.cpp
opts/SkBitmapProcState_matrix_neon.h
opts/SkXfermode_opts_arm_neon.cpp
opts/SkPMFloat_neon.h
opts/SkXfermode_opts_arm_neon.h
opts/SkColor_opts_neon.h
opts/SkMorphology_opts_neon.cpp
opts/Sk4x_neon.h
opts/SkBlitMask_opts_arm_neon.cpp
opts/SkBlurImage_opts_neon.cpp
core/SkUtilsArm.cpp
opts/SkBitmapProcState_arm_neon.cpp
opts/SkBitmapProcState_opts_arm.cpp
opts/SkBlurImage_opts_arm.cpp
opts/SkBlitMask_opts_arm.cpp
opts/memset.arm.S
opts/SkBlitRow_opts_arm_neon.h
opts/SkBlitMask_opts_arm_neon.h
opts/SkXfermode_opts_arm_neon.cpp
opts/SkXfermode_opts_arm_neon.h
opts/SkTextureCompression_opts_arm.cpp
opts/SkMorphology_opts_arm.cpp
opts/SkXfermode_opts_arm.cpp
opts/SkUtils_opts_arm.cpp
opts/SkBlitMask_opts_arm_neon.cpp
EOF

cat >/dev/null <<EOF
removestuff "." <<EOF
browser/search/hotword_audio_history_handler.cc
browser/search/hotword_audio_history_handler.h
browser/search/hotword_client.h
browser/search/hotword_service.cc
browser/search/hotword_service.h
browser/search/hotword_service_factory.cc
browser/search/hotword_service_factory.h
./chrome/browser/resources/hotword_helper
./chrome/browser/resources/hotword
./chrome/browser/resources/hotword_audio_verification
./chrome/browser/extensions/api/hotword_private
./chrome/test/data/extensions/hotword
./chrome/test/data/extensions/api_test/hotword_private
./chrome/test/data/extensions/api_test/hotword_private/hotwordSession
./chrome/browser/resources/app_list/hotword_nacl.nmf                                                          
./chrome/browser/resources/options/hotword_search_setting_indicator.js
./chrome/browser/resources/options/hotword_confirm_dialog.js
./chrome/browser/resources/options/hotword_confirm_overlay.html
./chrome/browser/resources/options/hotword_confirm_overlay.css
./chrome/browser/resources/options/hotword_search_setting_indicator.css
./chrome/browser/search/hotword_service_factory.cc
./chrome/browser/search/hotword_service_factory.h
./chrome/browser/search/hotword_audio_history_handler.h
./chrome/browser/search/hotword_client.h
./chrome/browser/search/hotword_service.cc
./chrome/browser/search/hotword_audio_history_handler.cc
./chrome/browser/search/hotword_installer_browsertest.cc
./chrome/browser/search/hotword_service_unittest.cc
./chrome/browser/search/hotword_service.h
./chrome/browser/extensions/hotword_browsertest.cc
./chrome/common/extensions/api/hotword_private.idl
out

./chrome/browser/task_manager/background_information.cc
./chrome/browser/task_manager/background_information.h
chrome/browser/plugins/chrome_plugin_service_filter.h
content/public/browser/plugin_service.h
EOF
#content/public/common/webplugininfo.h

#./chrome/app/theme/default_100_percent/common/app_list_mic_hotword_off.png
#./chrome/app/theme/default_100_percent/common/notification_hotword_icon.png
#./chrome/app/theme/default_100_percent/common/app_list_mic_hotword_on.png
#./chrome/app/theme/default_200_percent/common/app_list_mic_hotword_off.png
#./chrome/app/theme/default_200_percent/common/notification_hotword_icon.png
#./chrome/app/theme/default_200_percent/common/app_list_mic_hotword_on.png

#removestuff "." <<EOF
#third_party/llvm-build
#EOF
  #TEMP:
  cat >/dev/null <<EOFF
  msg2 "Removing a ton of stuff from source..."
removestuff "." <<EOF
chrome/browser/ui/views/frame/minimize_button_metrics_win.cc
chrome/browser/ui/views/frame/minimize_button_metrics_win.h
chrome/browser/ui/webui/signin
chrome/browser/ui/webui/print_preview
chrome/browser/ui/webui/password_manager_internals
chrome/browser/ui/webui/local_discovery
chrome/browser/ui/webui/metrics_handler.cc
chrome/browser/ui/webui/signin_internals_ui.h
chrome/browser/ui/webui/signin_internals_ui.cc
chrome/browser/ui/webui/plugins_ui.h
printing
remoting
device
jingle
sync
chrome/test
pdf
content/test
base/test
third_party/mojo/src/mojo/public/c/system/tests
third_party/mojo/src/mojo/edk/test
third_party/mojo/src/mojo/edk/js/test
third_party/mojo/src/mojo/edk/js/tests
third_party/WebKit/Source/wtf/wtf_tests.gyp
third_party/WebKit/Source/wtf/testing
third_party/WebKit/Source/platform/testing
third_party/WebKit/Source/platform/speech
third_party/WebKit/Source/platform/blink_platform_tests.gyp
third_party/WebKit/Source/platform/graphics/test
third_party/WebKit/Source/platform/image-decoders/testing
third_party/WebKit/Source/core/plugins/testing
third_party/WebKit/Source/core/testing
third_party/WebKit/Source/bindings/tests
third_party/WebKit/Source/web/tests
third_party/WebKit/Source/web/web_tests.gyp
third_party/WebKit/Source/modules/serviceworkers/testing
third_party/WebKit/Source/modules/vibration
third_party/WebKit/Source/modules/geolocation
third_party/WebKit/Source/modules/navigatorcontentutils/testing
third_party/WebKit/Source/modules/speech
third_party/WebKit/LayoutTests
third_party/WebKit/ManualTests
third_party/WebKit/PerformanceTests
sandbox/linux/tests
sandbox/win/tests
native_client
android_webview
tools/telemetry
build/android
build/find_isolated_tests.py
ios
sandbox/linux/seccomp-bpf/bpf_tests.h
tools/valgrind
extensions/extensions_tests.gyp
extensions/extensions_tests.gypi
testing
./ui/base/ui_base_tests.isolate
./content/content_gl_tests.isolate
./chrome/sync_integration_tests.isolate
./chrome/angle_end2end_tests.isolate
./chrome/browser_tests.isolate
./chrome/installer/mini_installer_tests.isolate
./chrome/unit_tests.isolate
./chrome/tab_capture_end2end_tests.isolate
./chrome/gl_tests.isolate
./chrome/interactive_ui_tests.isolate
ui/ios
components/test
components/components_tests.gyp
skia/skia_tests.gyp
ui/base/ui_base_tests.gyp
ui/gfx/gfx_tests.gyp
ui/views/controls/webview/webview_tests.gyp
third_party/libyuv/tools/valgrind-libyuv/libyuv_tests.*
third_party/mesa/src/src/glsl/tests
third_party/mesa/src/src/gallium/drivers/r300/compiler/tests
third_party/mesa/src/src/gallium/auxiliary/util/u_format_tests.*
third_party/skia/platform_tools/android/tests
third_party/boringssl/boringssl_tests.gypi
third_party/boringssl/src/util/all_tests.go
third_party/boringssl/src/crypto/cipher/test
third_party/boringssl/boringssl_tests.gyp
third_party/libvpx/source/libvpx/test
third_party/webdriver/pylib/test
third_party/angle/tests
third_party/webgl/src/sdk/tests
third_party/webgl/src/conformance-suites/1.0.0/conformance/more/all_tests.html
third_party/webgl/src/conformance-suites/1.0.1/conformance/more/all_tests.html
third_party/webgl/src/conformance-suites/1.0.2/conformance/more/all_tests.html
third_party/webgl/src/conformance-suites/1.0.3/conformance/more/all_tests.html
third_party/chromite/cbuildbot/run_tests.py
third_party/WebKit/Source/devtools/scripts/jsdoc-validator/run_tests.py
third_party/WebKit/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests.py
third_party/WebKit/Tools/Scripts/webkitpy/webgl/update_webgl_conformance_tests.py
third_party/mojo/mojo_edk_tests.gyp
third_party/mojo/src/mojo/public/tools/bindings/pylib/mojom/generate/*_tests.py
third_party/mojo/src/mojo/public/interfaces/bindings/tests/regression_tests.mojom
third_party/icu/source/test
third_party/pyelftools/test
blink/tools/run_layout_tests.*
win8
gin/test/run_js_tests.cc
content/browser/resources/gpu/browser_bridge_tests.js
content/shell/android
content/content_*_tests.gyp
content/content_*_tests.gypi
content/common/gpu/client/gpu_in_process_context_tests.cc
content/common/gpu/client/gpu_context_tests.h
ppapi/generators/idl_tests.py
ppapi/generate_ppapi_include_tests.py
ppapi/ppapi_tests.gypi
net/tools/flip_server/run_all_tests.cc
breakpad/src/client/windows
media/ffmpeg/ffmpeg_regression_tests.cc
cc/blink/cc_blink_tests.gyp
./cc/cc_tests.gyp
gpu/perftests
./gpu/khronos_glcts_support/generate_khronos_glcts_tests.py
./gpu/gles2_conform_support/generate_gles2_conform_tests.py
./ipc/ipc_fuzzing_tests.cc
./chromecast/chromecast_tests.gypi
base/android
chrome/chrome_tests.gypi
third_party/mojo/src/mojo/public/cpp/test_support/BUILD.gn
build/secondary/testing
build/config/android
content/content_tests.gypi
chrome/browser/resources/chromeos/chromevox/chromevox_tests.gypi
chrome/browser/resources/chromeos
components/content_settings/core/test
components/bookmarks/test
chrome/chrome_tests_unit.gypi
third_party/mojo_services/src/view_manager/public/cpp/tests
third_party/mojo/src/mojo/public/cpp/system/tests
third_party/mojo/src/mojo/public/cpp/utility/tests
third_party/mojo/src/mojo/public/cpp/bindings/tests
third_party/mojo/src/mojo/public/cpp/application/tests
third_party/mojo/src/mojo/public/cpp/environment/tests
mojo/converters/surfaces/tests
third_party/mojo/src/mojo/public/cpp/bindings/tests
media/cast/cast_testing.gypi
courgette/testdata
EOF

removestuff "net/quic" <<EOF
quic_connection_logger.h
quic_connection_logger.cc
EOF

removestuff "chrome/browser" <<EOF
autofill
captive_portal
drive
feedback
geolocation
google
local_discovery
metrics
notifications
password_manager
pdf
performance_monitor
printing
safe_browsing
signin
speech
sync
sync_file_system
crash_upload_list.cc
crash_upload_list.h
crash_upload_list_win.cc
crash_upload_list_win.h
pepper_broker_infobar_delegate.cc
pepper_broker_infobar_delegate.h
pepper_flash_settings_manager.cc
pepper_flash_settings_manager.h
EOF

removestuff "chrome/browser/extensions/api" <<EOF
braille_display_private
cloud_print_private
desktop_capture
easy_unlock_private
feedback_private
gcd_private
hotword_private
image_writer_private
EOF

removestuff "chrome/browser/extensions" <<EOF
blacklist.cc
blacklist_factory.cc
blacklist_factory.h
blacklist.h
blacklist_state_fetcher.cc
blacklist_state_fetcher.h
blacklist_state_fetcher_unittest.cc
blacklist_unittest.cc
extension_storage_monitor.cc
extension_storage_monitor_factory.cc
extension_storage_monitor_factory.h
extension_storage_monitor.h
EOF

removestuff "chrome/renderer/resources/extensions" <<EOF
image_writer_private_custom_bindings.js
EOF

removestuff "chrome/utility" <<EOF
image_writer
EOF

removestuff "chrome/common" <<EOF
cloud_print
local_discovery
safe_browsing
tts_messages.h
tts_utterance_request.cc
tts_utterance_request.h
EOF

removestuff "chrome/common/extensions" <<EOF
image_writer
extension_metrics.cc
extension_metrics.h
EOF

removestuff "chrome/common/extensions/api" <<EOF
notifications
plugins
speech
braille_display_private.idl
desktop_capture.json
dial.idl
easy_unlock_private.idl
extension_api_unittest.cc
feedback_private.idl
gcd_private.idl
hangouts_private.idl
hotword_private.idl
image_writer_private.idl
inline_install_private.idl
location.idl
mdns.idl
metrics_private.json
music_manager_private.idl
notification_provider.idl
notifications.idl
push_messaging.idl
screenlock_private.idl
signed_in_devices.idl
tts_engine.json
tts.json
EOF

removestuff "base" <<EOF
metrics
EOF
#  rm -rf -- 'base/metrics'
#XXX: use this in the '1' folder(no relation to '1's inside sed) where i moved the files/folder, to get a list to put below: ls -1 | sed -re 's|(.*)/$|\1|g'
#read -r -d '' -a components_files <<EOF
removestuff "components" <<EOF
audio_modem
autofill
auto_login_parser
cloud_devices
copresence
feedback
google
handoff
language_usage_metrics
metrics
navigation_metrics
pairing
password_manager
pdf
plugins
printing
proximity_auth
rappor
signin
startup_metric_utils
storage_monitor
sync_driver
wifi
wifi_sync
audio_modem.gypi
autofill.gypi
autofill_strings.grdp
auto_login_parser.gypi
captive_portal.gypi
cloud_devices.gypi
copresence.gypi
feedback.gypi
google.gypi
handoff.gypi
language_usage_metrics.gypi
metrics.gypi
navigation_metrics.gypi
pairing.gypi
password_manager.gypi
password_manager_strings.grdp
pdf.gypi
pdf_strings.grdp
plugins.gypi
printing.gypi
proximity_auth.gypi
signin.gypi
startup_metric_utils.gypi
storage_monitor.gypi
wifi.gypi
wifi_sync.gypi
EOF
#  pushd components
#  rm -rf -- ${components_files[@]}
#  popd
  
#read -r -d '' -a third_party_files <<EOF
removestuff "third_party" <<EOF
accessibility-audit
adobe
analytics
libjingle
libphonenumber
libsrtp
libusb
safe_browsing
speech-dispatcher
speex
usb_ids
v4l2capture
v4l-utils
webrtc
pdfium
EOF

removestuff "extensions" <<EOF
test
renderer/api_test_base.cc
EOF

find . -type f -name '*_unittest*' -o -type f -name '*_test_*' -o -type f -name '*_tests_*' | xargs rm -f -- 
EOFF

#  rm -rf -- ${third_party_files[@]}
#  popd
#  exit 1

#
#then do whatever:
#  set |grep _CC
#  exit 1
#  set
#  exit 1

#  rm -rf "${srcdir}/python-path"
#  mkdir -p "${srcdir}/python-path"
#  [ -L "${srcdir}/python-path/python" ] || ln -s "/usr/bin/python2" "${srcdir}/python-path/python"
#  export PATH="${srcdir}/python-path:$PATH"


  # Use Python 2
#  msg2 "Make sure use Python 2"
#  find . -not \( -path ./.git -prune \) -type f -exec sed -i -r \

  #-prune is not needed though:
#  find . -not \( -path */.git/* -prune \) -type f -exec sed -i -r \
#    -e 's|/usr/bin/python$|&2|g' \
#    -e 's|/usr/bin/env python$|&2|g' \
#    -e 's|(/usr/bin/python2)\.4$|\1|g' \
#    {} +

#XXX: both in all.patch :
  msg2 "Fix to save configuration in ~/.config/chromium-dev"
  sed -e "s|'filename': 'chromium-browser'|'filename': 'chromium-dev'|" \
      -e "s|'confdir': 'chromium'|'confdir': 'chromium-dev'|" \
      -i "chrome/chrome_exe.gypi"
  sed -e 's|config_dir.Append("chromium")|config_dir.Append("chromium-dev")|' \
      -i "chrome/common/chrome_paths_linux.cc"

#  if test "$GYP" = "1"; then
#  msg2 "fix mispelled warning flag" #TODO: is this still needed or was I introducing that with above ^
#  sed -e "s|'-Wno-unused-local-typedef'|'-Wno-unused-local-typedefs'|g" \
#      -i "build/common.gypi"
  #well this isn't working either, but maybe it works in some places!
  #when it doesn't work, shows:
  #warning: unknown warning option '-Wno-unused-local-typedefs' [-Wunknown-warning-option]
  #1 warning generated.
#  fi

#XXX: already in all.patch :
#  msg2 "fix message center when notifications are disabled"
#  sed -e "s|#if !defined(OS_ANDROID) && !defined(OS_IOS)||" \
#      -e "s|#error This file should only be used in Android or iOS builds.||" \
#      -e "s|#endif||" \
#      -i "ui/message_center/dummy_message_center.cc"

#nolonger applies:
#      -e 's|config_dir.Append("chrome-frame")|config_dir.Append("chrome-frame-dev")|' \

  # Make it possible to remove third_party/adobe

  if test "$GYP" = "1"; then #probably unneeded for gyp too
    _flapfile="${srcdir}/flapper_version.h"
    [ -f "$_flapfile" ] || echo > "$_flapfile"
  fi


  # Patch from crbug (chromium bugtracker)

  # Misc Patches:


#  if [ "${_use_clang}" = "1" ]; then
#  # clang 3.4 doesn't support this option
#  sed '/-Wno-absolute-value/d' -i build/common.gypi
#  fi

#  msg2 "Remove unnecessary components to save space"
  # Remove most bundled libraries. Some are still needed. supposed to be used only for the .tar archive not the repo, says: build/linux/unbundle/README
#  build/linux/unbundle/remove_bundled_libraries.py \
#	'base/third_party/dmg_fp' \
#	'base/third_party/dynamic_annotations' \
#	'base/third_party/icu' \
#	'base/third_party/nspr' \
#	'base/third_party/superfasthash' \
#	'base/third_party/symbolize' \
#	'base/third_party/valgrind' \
#	'base/third_party/xdg_mime' \
#	'base/third_party/xdg_user_dirs' \
#	'breakpad/src/third_party/curl' \
#	'chrome/third_party/mozilla_security_manager' \
#	'courgette/third_party' \
#	'crypto/third_party/nss' \
#	'native_client/src/third_party/dlmalloc' \
#	'net/third_party/mozilla_security_manager' \
#	'net/third_party/nss' \
#	'third_party/WebKit' \
#	'third_party/angle' \
#	'third_party/angle/src/third_party/compiler' \
#	'third_party/brotli' \
#	'third_party/cacheinvalidation' \
#	'third_party/cld_2' \
#	'third_party/cros_system_api' \
#	'third_party/cython/python_flags.py' \
#	'third_party/dom_distiller_js' \
#	'third_party/dom_distiller_js/package/proto_gen/third_party/dom_distiller_js' \
#	'third_party/ffmpeg' \
#	'third_party/fips181' \
#	'third_party/flot' \
#	'third_party/hunspell' \
#	'third_party/iccjpeg' \
#	'third_party/jsoncpp' \
#	'third_party/jstemplate' \
#	'third_party/khronos' \
#	'third_party/leveldatabase' \
#	'third_party/libaddressinput' \
#	'third_party/libjingle' \
#	'third_party/libphonenumber' \
#	'third_party/libsrtp' \
#	'third_party/libusb' \
#	'third_party/libvpx' \
#	'third_party/libvpx/source/libvpx/third_party/x86inc' \
#	'third_party/libwebm' \
#	'third_party/libxml/chromium' \
#	'third_party/libXNVCtrl' \
#	'third_party/libyuv' \
#	'third_party/lss' \
#	'third_party/lzma_sdk' \
#	'third_party/mesa' \
#	'third_party/modp_b64' \
#	'third_party/mt19937ar' \
#	'third_party/npapi' \
#	'third_party/opus' \
#	'third_party/ots' \
#	'third_party/pdfium' \
#	'third_party/pdfium/third_party/logging.h' \
#	'third_party/pdfium/third_party/macros.h' \
#	'third_party/pdfium/third_party/numerics' \
#	'third_party/pdfium/third_party/template_util.h' \
#	'third_party/polymer' \
#	'third_party/protobuf' \
#	'third_party/qcms' \
#	'third_party/readability' \
#	'third_party/sfntly' \
#	'third_party/skia' \
#	'third_party/smhasher' \
#	'third_party/sqlite' \
#	'third_party/tcmalloc' \
#	'third_party/tlslite' \
#	'third_party/trace-viewer' \
#	'third_party/trace-viewer/third_party/jszip' \
#	'third_party/trace-viewer/third_party/tvcm' \
#	'third_party/trace-viewer/third_party/tvcm/third_party/d3' \
#	'third_party/trace-viewer/third_party/tvcm/third_party/gl-matrix' \
#	'third_party/trace-viewer/third_party/tvcm/third_party/polymer' \
#	'third_party/undoview' \
#	'third_party/usrsctp' \
#	'third_party/webdriver' \
#	'third_party/webrtc' \
#	'third_party/widevine' \
#	'third_party/x86inc' \
#	'third_party/zlib/google' \
#	'url/third_party/mozilla' \
#	'v8/src/third_party/kernel' \
#	'v8/src/third_party/valgrind' \
#	'v8/third_party/fdlibm' \
#	--do-remove || true

#  msg2 "Setup NaCl/PNaCl SDK: Download and install NaCl/PNaCl toolchains"
#  build/download_nacl_toolchains.py --packages nacl_x86_newlib,pnacl_newlib,pnacl_translator
#this says:
#Can't find '/tmp/2/src/chromium-dev-git/native_client/build/package_version/package_version.py'
#Presumably you are intentionally building without NativeClient.
#Skipping NativeClient toolchain download.

#set -x
    msg2 "Patching sources"
    #   Patch sources from Gentoo
    #dontdo: avoid repatching this on subsequent calls - ok done, BUT, patch these when fetch above fails and you rerun which means gclient sync above gets run  the second time.;;;; wait a second this isn't needed because we git stash all changes! so reapplying patches makes sense

#fixed: this isn't working maybe due to -E and -o pipefail ! fix it or find another way; still not fixed
    #don't pipefail:
#    set +o pipefail
#    set +E
#    echo $-
#    #ehxB
#    trap -p
#    #fixed: it's because of this coupled with: set -e
#    #trap -- 'error_function $pkgfunc' ERR

    lepatch -Np0 -i "${srcdir}/chromium-system-jinja-r7.patch" # | grep -E "(FAILED|ignored)" ; true
##    patch -p1 -i "${srcdir}/chromium-libsecret-r0.patch"
###    patch -p1 -i "${srcdir}/${patch3}"
#    lepatch -Np1 -i "${srcdir}/${patch4}"
##    lepatch -Np1 -i "${srcdir}/${patch5}"
###    patch -p1 -i "${srcdir}/${patch6}"
#    lepatch -Np1 -i "${srcdir}/${patch7}"
#    lepatch -Np1 -i "${srcdir}/${patch8}"
##    lepatch -Np1 -i "${srcdir}/${patch9}"
#    lepatch -Np1 -i "${srcdir}/${patch10}"
    for eachpatch in "${allpatches[@]}"; do
      lepatch -Np1 -i "${srcdir}/${eachpatch}"
    done
#TEMP:    lepatch -Np1 -i "${srcdir}/${patchall}" #| grep -E "(FAILED --|ignored)" ; true
#    ec="${PIPESTATUS[0]}"
#    if test "$ec" -ne 0; then
#      error "patching failed! reapply changes in .rej files above and remake the patch, update patch file and re-execute this."
#      exit $ec
#    fi
    #restore
#    set -o pipefail
#    set -E
    msg2 "done sources"


  mkdir -p "${_reldir}"

  if test "$GYP" = "0"; then
#    gn --root=src gen /tmp/out/Default
#    pwd #already in src
    cp -- "../args.gn" "${_reldir}"
#    "${srcdir}/pythonic"
      gn gen "${_reldir}"
  fi

  msg2 "runhooks"
  #"${srcdir}/pythonic"
  gclient runhooks   #can't run this here because it runs gyp_chromium!
#  pushd "${_srcfolder}"
#FIXME: I should make runhooks run it like this:  OK doing this in build() below; ok this may not work for gn ? clang: error: unsupported argument '--version' to option 'Xassembler'
#compiler_version.py failed to execute: ccache clang++ -Qunused-arguments -Xassembler --version -x assembler -c /dev/null
#  build/gyp_chromium --depth=. "${_flags[@]}" "${_use_system[@]}"
#  popd
}

build() {
  export PATH="${srcdir}/python-path:$PATH"
  msg2 "cleaning .d files from ${_reldir}"
  #because of errors like this:
  #ninja: error: gen/content/resources.d: depfile has multiple output paths
  cd "${_reldir}"
  #this won't work if there are no files:
#  find . -name '*.d' -type f -print0 | xargs -0 -- rm --one-file-system --verbose --
  find . -name '*.d' -type f -print0 -exec rm --one-file-system --verbose -- {} \;
  msg2 "continuing normally..."
  #cd "chromium-${pkgver}"
  cd "${_srcfolder}"
  echo "$CC"
  pwd
#  set
#  exit 2

  #######################
  ## -- Let's build -- ##
  #######################
  msg2 "Building Chromium..."

  if test "$GYP" = "1"; then
    if [ "${_use_clang}" = "0" ]; then
      # Silence "typedef 'x' locally defined but not used" warnings
      CFLAGS+=' -Wno-unused-local-typedef'
      #warning: unknown warning option '-Wno-unused-local-typedefs' [-Wunknown-warning-option]
    fi
  fi

  # NOTES:
  # -Denable_sql_database=0                  | http://crbug.com/22208
  # -Dlogging_like_official_build=1          | Save space by removing DLOG and DCHECK messages (about 6% reduction).
  # -Dlinux_use_gold_flags=0                 | Never use bundled gold binary. Disable gold linker flags for now.
  # -Dusb_ids_path=/usr/share/hwdata/usb.ids | Use the file at run time instead of effectively compiling it in.

  if test "$GYP" = "1"; then
#attempting to not use any keys!
#    -Dgoogle_api_key="${_google_api_key}"
#    -Dgoogle_default_client_id="${_google_default_client_id}"
#    -Dgoogle_default_client_secret="${_google_default_client_secret}"
# options are at build/common.gypi
  local _flags=(
  -Denable_mpeg2ts_stream_parser=0 #already 0
  -Ddisable_glibcxx_debug=1
  -Dv8_enable_i18n_support=0
  -Ddisable_nacl_untrusted=1
  -Djava_bridge=0
  -Ddebug_devtools=0
#  -Dandroid_lint=0
  -Demma_coverage=0 # already 0
  -Duse_official_google_api_keys=0
  -Dvideo_hole=0
  -Denable_hangout_services_extension=0
  -Denable_wifi_bootstrapping=0
  -Denable_service_discovery=0
  -Denable_managed_users=0
  -Denable_plugin_installation=0
  -Duse_xi2_mt=0 # multitouch stuff
  -Ddisable_ftp_support=0
  -Ddisable_file_support=0
  -Denable_task_manager=1 # already 1
  -Denable_background=0
  -Denable_prod_wallet_service=0
  -Denable_autofill_dialog=0 # already 0
  -Denable_themes=0
  -Denable_session_service=0 # if something fails, enable this
  -Denable_webrtc=0
  -Denable_spellcheck=1
  -Denable_printing=0
  -Denable_google_now=0
  -Denable_extensions=1 # already 1 by default
  -Denable_pre_sync_backup=0 # already 0 by default
  -Denable_one_click_signin=0 # already 0 by default
  -Dnotifications=0
  -Denable_web_speech=1
  -Dsafe_browsing=0
  -Dconfiguration_policy=1 #set to 1 if compilation errors
  -Dremoting=0
  -Dcomponent=shared_library
  -Dtracing_like_official_build=1
  -Dfastbuild=2
  -Ddont_embed_build_metadata=1
    -Ddisable_glibc=1
    -Ddisable_fatal_linker_warnings=1
    -Dffmpeg_branding=Chrome
    -Dflapper_version_h_file="${_flapfile}"
    -Dicu_use_data_file_flag=0
    -Dlibspeechd_h_prefix=speech-dispatcher/
    -Dlinux_link_gnome_keyring="${_use_gnome}"
    -Dlinux_link_gsettings="${_use_gnome}"
    -Dlinux_link_libpci=1
    -Dlinux_link_libspeechd=1
    -Dlinux_strip_binary=1
    -Dlinux_use_bundled_binutils=0
    -Dlinux_use_bundled_gold=0
    -Dlinux_use_gold_flags=0
    -Dlogging_like_official_build=1
    -Dno_strict_aliasing=1
    -Dproprietary_codecs=1 #must for some youtube videos like: https://www.youtube.com/watch?v=PR6CqWpNrS0
    -Drelease_extra_cflags="$CFLAGS"
    -Dremove_webcore_debug_symbols=1  #required as per: https://code.google.com/p/chromium/wiki/LinuxBuildInstructionsPrerequisites#Arch_Linux_Setup
    -Dtarget_arch="${_target_arch}"
    -Dusb_ids_path=/usr/share/hwdata/usb.ids
    -Duse_gconf=0
    -Duse_gnome_keyring="${_use_gnome}"
    -Duse_pulseaudio="${_use_pulseaudio}"
    -Dlinux_link_pulseaudio="${_use_pulseaudio}"
    -Dpython_ver=2.7
    -Ddisable_nacl=1
    -Ddisable_pnacl=1
    -Ddcheck_always_on=0
    -Dwerror=  #prevent warnings from failing build https://code.google.com/p/chromium/wiki/LinuxBuildInstructions#Sample_configurations
    )
#    -Ddisable_chromoting=1  #not a real option now, is it?
  fi

  if [ "${_use_clang}" = "1" ]; then
    # -Dclang=1 use clang instead of GCC
    # -Dclang_use_chrome_plugins=1 fail if use clang minor of v3.5. disable this
    if test "$GYP" = "1"; then
      _flags+=(
        -Dclang=1
        -Dclang_use_chrome_plugins=0
        )
    fi
    export CC="clang"
    export CXX="clang++"
    export CXXFLAGS="${CXXFLAGS} -Wno-unknown-warning-option"
    #no effect:
#    CXXFLAGS+=" -Wno-empty-body"
#    CFLAGS+=" -Wno-empty-body"
  fi

#msg2 "-Duse_gnome_keyring=\"${_use_gnome}\""
  # Re-configure bundled ffmpeg
#  msg2 "Configuring bundled ffmpeg"
#  pushd third_party/ffmpeg # > /dev/null
#  local _build_ffmpeg_args=""
#  [ "${CARCH}" = "i686" ] && _build_ffmpeg_args=" --disable-asm"
#  "${srcdir}/pythonic" chromium/scripts/build_ffmpeg.py linux ${_target_arch} --branding=Chrome -- ${_build_ffmpeg_args}
#  "${srcdir}/pythonic" chromium/scripts/copy_config.sh
#  "${srcdir}/pythonic" chromium/scripts/generate_gyp.py
#  popd #> /dev/null

  msg2 "something"

  # CFLAGS are passed through -Drelease_extra_cflags=
  export -n CFLAGS CXXFLAGS

  if test "$GYP" = "1"; then
    #FIXEd: is this really needed? - apparently so
    # Changing bundle libraries to system ones
  #  "${srcdir}/pythonic" build/linux/unbundle/replace_gyp_files.py --undo  #not working python script fails
    #"${srcdir}/pythonic"
    build/linux/unbundle/replace_gyp_files.py "${_use_system[@]}"
  fi

  msg2 "CC=$CC"
  msg2 "CXX=$CXX"
  # https://code.google.com/p/chromium/wiki/CCacheMac
  export CC="ccache clang -Qunused-arguments"
  export CXX="ccache clang++ -Qunused-arguments"
#  export CC="clang -Qunused-arguments"
#  export CXX="clang++ -Qunused-arguments"
  #export CCACHE_CPP2=yes
  #might need that ^ 
  # ^ http://petereisentraut.blogspot.com/2011/05/ccache-and-clang.html?showComment=1390921308307#c2753775068550152695
  msg2 "CC=$CC"
  msg2 "CXX=$CXX"

  if test "$GYP" = "1"; then
    #this is equivalent: gclient runhooks
##    "${srcdir}/pythonic"
    build/gyp_chromium --depth=. "${_flags[@]}" "${_use_system[@]}"
  fi


  if [ "${_use_pax}" = "1" ]; then
    # Build mksnapshot and pax-mark it.
    #"${srcdir}/pythonic"
    ninja -C "${_reldir}" -v "mksnapshot"
    #"${srcdir}/pythonic"
    paxctl -cm "${_reldir}/mksnapshot"
  fi

  msg2 "ninja-ing"
#  "${srcdir}/pythonic" ninja -l 90 -f "${_srcfolder}/out/Release/build.ninja" -C "${_reldir}" -v chrome chrome_sandbox

#  mkdir -p "${_reldirtmp}"
#  #out/Release will point to /tmp/out/Release so it's in RAM (tmpfs)
#  #mv -t target src
#  mv -vft "${_reldirtmp}" "${_reldir}/"
#  #ln -T target linkname
#  ln -sT "${_reldirtmp}" "${_reldir}
  #"${srcdir}/pythonic"
  ninja -C "${_reldir}" chrome chrome_sandbox
  #chromedriver

  if [ "${_use_pax}" = "1" ]; then
    # Pax-mark again
    #"${srcdir}/pythonic"
    paxctl -cm "${_reldir}/chrome"
  fi
}

package() {
  pwd
  install -Dm644 chromium-dev.default "${pkgdir}/etc/chromium-dev/default"
  install -Dm755 chromium-dev.sh "${pkgdir}/usr/bin/chromium-dev"
  install -Dm644 chromium-dev.desktop "${pkgdir}/usr/share/applications/chromium-dev.desktop"

  cd "${_srcfolder}"
  pwd
  install -Dm644 "LICENSE" "${pkgdir}/usr/share/licenses/chromium-dev/LICENSE"
#  cd "./out/Release"
#  cd "chromium-${pkgver}/out/Release"
  cd "${_reldir}"
  install -Dm755 chrome "${pkgdir}/usr/lib/chromium-dev/chromium-dev"
  install -Dm4755 -o root -g root chrome_sandbox "${pkgdir}/usr/lib/chromium-dev/chrome-sandbox"
#  install -Dm755 chromedriver "${pkgdir}/usr/lib/chromium-dev/chromedriver"
#  ln -s /usr/lib/chromium-dev/chromedriver "${pkgdir}/usr/bin/chromedriver-dev"
  install -Dm644 chrome_100_percent.pak "${pkgdir}/usr/lib/chromium-dev/chrome_100_percent.pak"
  if test "$GYP" = '1'; then
    install -Dm644 content_resources.pak "${pkgdir}/usr/lib/chromium-dev/content_resources.pak"
  else
    install -Dm644 gen/content/content_resources.pak "${pkgdir}/usr/lib/chromium-dev/content_resources.pak"
    install -Dm644 natives_blob.bin "${pkgdir}/usr/lib/chromium-dev/natives_blob.bin"
    install -Dm644 snapshot_blob.bin "${pkgdir}/usr/lib/chromium-dev/snapshot_blob.bin"
  fi
  install -Dm644 keyboard_resources.pak "${pkgdir}/usr/lib/chromium-dev/keyboard_resources.pak"
  install -Dm644 resources.pak "${pkgdir}/usr/lib/chromium-dev/resources.pak"
  install -Dm755 libffmpegsumo.so "${pkgdir}/usr/lib/chromium-dev/libffmpegsumo.so"
  if test "$GYP" = '1'; then
    install -Dm755 libpdf.so "${pkgdir}/usr/lib/chromium-dev/libpdf.so"
    find lib -type f -name "*.so" -exec install -Dm644 '{}' "${pkgdir}/usr/lib/chromium-dev/{}" \;
  fi
  find locales -type f -name '*.pak' -exec install -Dm644 '{}' "${pkgdir}/usr/lib/chromium-dev/{}" \;
  install -Dm644 chrome.1 "${pkgdir}/usr/share/man/man1/chromium-dev.1"
  install -Dm644 icudtl.dat "${pkgdir}/usr/lib/chromium-dev/icudtl.dat"

  #TODO: remove these; check if needed; like remove package(don't upgrade) then install new one with these removed!
  for _size in 16 22 24 32 48 128 256; do
    case "${_size}" in
      16|32) _branding="${_srcfolder}/chrome/app/theme/default_100_percent/chromium" ;;
      *) _branding="${_srcfolder}/chrome/app/theme/chromium" ;;
    esac
    install -Dm644 "${_branding}/product_logo_${_size}.png" "${pkgdir}/usr/share/icons/hicolor/${_size}x${_size}/apps/chromium-dev.png"
  done

  #install -Dm755 libppGoogleNaClPluginChrome.so "${pkgdir}/usr/lib/chromium-dev/libppGoogleNaClPluginChrome.so"
#  install -Dm755 nacl_helper "${pkgdir}/usr/lib/chromium-dev/nacl_helper"

#this exists tho:
#  install -Dm755 nacl_helper_bootstrap "${pkgdir}/usr/lib/chromium-dev/nacl_helper_bootstrap"

#  [ "${CARCH}" = "i686" ] && install -Dm755 nacl_irt_x86_32.nexe "${pkgdir}/usr/lib/chromium-dev/nacl_irt_x86_32.nexe"
#  [ "${CARCH}" = "x86_64" ] && install -Dm755 nacl_irt_x86_64.nexe "${pkgdir}/usr/lib/chromium-dev/nacl_irt_x86_64.nexe"

#  [ "${_use_gnome}" = "1" ] && install -Dm644 "${srcdir}/chromium-dev.xml" "${pkgdir}/usr/share/gnome-control-center/default-apps/chromium-dev.xml"

  # Manually strip binaries so that 'nacl_irt_*.nexe' is left intact
  #strip $STRIP_BINARIES "${pkgdir}/usr/lib/chromium-dev/"{chromium-dev,chrome-sandbox,nacl_helper{,_bootstrap}} #,chromedriver

#  maybe don't faqin' strip: FIXME: when debug is on (for gn , it's set in args.gn !)
#  strip $STRIP_BINARIES "${pkgdir}/usr/lib/chromium-dev/"{chromium-dev,chrome-sandbox} #,chromedriver
#  strip $STRIP_SHARED "${pkgdir}/usr/lib/chromium-dev/libffmpegsumo.so"
  if test "$GYP" = '1'; then
    strip $STRIP_SHARED "${pkgdir}/usr/lib/chromium-dev/libpdf.so"
  fi
  #strip $STRIP_SHARED "${pkgdir}/usr/lib/chromium-dev/libppGoogleNaClPluginChrome.so"
}




